package com.fare.taluo.core.domain.config.channel;

import java.util.List;
import javax.persistence.Column;
import javax.persistence.Table;
import com.dayatang.domain.Entity;
import com.dayatang.domain.InstanceFactory;
import com.dayatang.domain.QuerySettings;
import com.fare.taluo.base.ddd.domain.baseentity.BaseEntity2;
import com.fare.taluo.core.domain.config.line.FlightInfoEntity;

@javax.persistence.Entity
@Table(name="FDC_AIR_COMPANY")
@SuppressWarnings("serial")
public class AirCompanyEntity extends BaseEntity2<FlightInfoEntity> implements Entity{
//	@Id
	@Column(name = "COMPANY_CODE")
	private String company_code;

	
	public String getName() {
		return name;
	}

	public String getCompany_code() {
		return company_code;
	}

	public void setCompany_code(String company_code) {
		this.company_code = company_code;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "NAME")
	private String name;
	
	
//	private static AirCompanyEntityReposity airCompanyEntityReposity = InstanceFactory.getInstance(AirCompanyEntityReposity.class);
	private static AirCompanyEntityReposity getAirCompanyEntityReposity(){
		return InstanceFactory.getInstance(AirCompanyEntityReposity.class);
	}
	public List<AirCompanyEntity> all(){
		return getAirCompanyEntityReposity().all();
	}
	public AirCompanyEntity findCompanNameByCode(String code){
		return getAirCompanyEntityReposity().findCompanNameByCode(code);
	}
	public AirCompanyEntity findCompanCodeByName(String name){
		return getAirCompanyEntityReposity().findCompanCodeByName(name);
	}

	@Override
	public boolean isNew() {
		return getId() == null ;
	}

	@Override
	public boolean existed() {
		if (isNew()) {
			return false;
		}
		return getRepository().exists(getClass(), id);
	}

	@Override
	public boolean notExisted() {
		return ! existed();
	}
	
	@Override
	public boolean existed(String propertyName, Object propertyValue) {
		List<?> entities = getRepository().find(QuerySettings.create(getClass()).eq(propertyName, propertyValue)); 
		return !(entities.isEmpty());
	}
}
